<?php

class Application_Plugin_PrivCheck extends Zend_Controller_Plugin_Abstract
{
   public function __construct(Zend_Acl $acl, Zend_Auth $auth)
   {
      $this->auth=$auth;
      $this->acl=$acl;
   }

   public function preDispatch(Zend_Controller_Request_Abstract $request)
   {
      $module=$request->  getModuleName();
      $controller=$request-> getControllerName();
      $page=$request-> getActionName();

      $resource=$module."_".$controller."_".$page;

      $identity=$this->auth->  getStorage()->read();

      if($identity==null)
      {
         $role='guest';
      }
      else
      {
         $role=$identity->role;
      }

      if(!$this->acl->isAllowed($role,$resource))
      {
         $request->  setModuleName('default')
                 ->  setControllerName('auth')
                 ->  setActionName('login');
      }
   }

   private $acl;
   private $auth;
}

?>
